<?php
require_once "../../../../mainfile.php";
require_once('MOD_GLOBALS.php');


	//ADMIN STUFF
	if(strpos ( $_SERVER['PHP_SELF'], 'admin')){
		ini_set('include_path', '../');
		$result = $xoopsDB->query("select * from ".$xoopsDB->prefix("calendar_events")." WHERE FL_APPRV = 'N' order by EVT_TS ASC") ;
		if(!isset($_SESSION['RNDid'])){
			$_SESSION['RNDid'] = 0;
		}else{
			$_SESSION['RNDid']++;
		}
		$domID = $_SESSION['RNDid'];

	//END USER STUFF
	}else{

		$result = $xoopsDB->query("
		SELECT *
		FROM
			".$xoopsDB->prefix("calendar_events")."
		WHERE
			FL_APPRV = 'Y' AND
			((EVT_TS_END = 0 AND (EVT_TS >= $BndryStrt AND EVT_TS <= $BndryEnd)) /*NO END DATE, THUS ONE DAY ONLY WITH NO END TIME SPECIFIED */
			OR (EVT_TS_END <> 0 AND (EVT_TS < $BndryEnd AND EVT_TS_END > $BndryStrt)) /*EVENT SPANS MULTIPLE DAYS */
			OR (EVT_TS_END <> 0 AND (EVT_TS >= $BndryStrt AND EVT_TS_END <= $BndryEnd)))

		ORDER BY
			EVT_TS ASC") ;

		if(!isset($_SESSION['RNDid'])){
			$_SESSION['RNDid'] = 0;
		}else{
			$_SESSION['RNDid']++;
		}
		$domID = $_SESSION['RNDid'];
	}
?>

<!-- CREATE EVENT ITEMS -->
<?PHP
	if ( $result ) {
		$rows = $xoopsDB->getAffectedRows($result);
		$x=1;
		$checked = false;
		$accHeight = $rows*27;
		if ($accHeight < 470){
			$accHeight = 470;
		}


		echo "<div dojoType='dijit.layout.AccordionContainer' duration='200' id='$domID' style='height:".$accHeight."px;'>";

			while($myrow = $xoopsDB->fetchArray($result)){

				//set selected accordian to be the first panel in list
				if((date("D  jS  h:i a",$myrow['EVT_TS']) == date("D  jS  h:i a",mktime()) || $x == ($rows)) && $checked != true)
				{
					$selected = 'true';
					$checked = true;
				}else
				{
					$selected = 'false';
				}

				//if there is an end time stamp then show it yo.
				/*if($myrow['EVT_TS_END'] != 0)
				{
					$endTime = date("D  jS  h:i a",$myrow['EVT_TS_END']).":";
				}else{
					$endTime = "";
				}*/


				echo "<div style='font-size:13px;' dojoType='dijit.layout.AccordionPane' selected='$selected' title='<b>".date("D  jS  h:i a",$myrow['EVT_TS']).":</b> ".$myrow['EVT_TITLE']." '>
					<table style='border:0px solid #cccccc;'>\n";

							if(trim($myrow['EVT_DSCR']) != ""){
							echo"
							<tr>
								<td style='$evntColHdrs'>Description:</td>
								<td style='".$eventColContent."'>".$myrow['EVT_DSCR']."</td>
							</tr>\n";
							}
							if(trim($myrow['EVT_LOC']) != ""){
							echo"
							<tr>
								<td style='$evntColHdrs'>Location:</td>
								<td style='".$eventColContent."'>".$myrow['EVT_LOC']."</td>
							</tr>\n";
							}
							if(trim($myrow['CON_NAME']) != ""){
							echo"
							<tr>
								<td style='$evntColHdrs'>Contact:</td>
								<td style='".$eventColContent."'>".$myrow['CON_NAME']."</td>
							</tr>\n";
							}
							if(trim($myrow['CON_NUM']) != ""){
							echo"
							<tr>
								<td style='$evntColHdrs'>Phone:</td>
								<td style='".$eventColContent."'>".$myrow['CON_NUM']."</td>
							</tr>\n";
							}
							if(trim($myrow['EMAIL']) != ""){
							echo"
							<tr>
								<td style='$evntColHdrs'>Email:</td>
								<td style='".$eventColContent."'><a href ='mailto:".$myrow['EMAIL']."?subject=RE: ".$myrow['EVT_TITLE']."'>".$myrow['EMAIL']."</a></td>
							</tr>\n";
							}
							if(trim($myrow['URL']) != ""){
							echo"
							<tr>
								<td style='$evntColHdrs'>Website:</td>
								<td style='".$eventColContent."'><a href ='".$myrow['URL']."' target='_blank'>".$myrow['URL']."</a></td>
							</tr>\n";
							}
							if(isset($_SESSION['XOOPS_ISADMIN']) && $_SESSION['XOOPS_ISADMIN'] == 1){
							echo"<tr><td colspan='2' style='border-top:0px solid #cccccc;padding-top:4px;'></td></tr>\n";

								if(strpos ( $_SERVER['PHP_SELF'], 'admin')){//show admin side buttons

									echo"
									<tr>
										<td colspan='2' style='padding-right:5px;'>".
											"<button dojoType=\"dijit.form.Button\" onClick=\"eventEdit('".$myrow['ID']."');\" style=\"height: 50px;\">Edit</button>" .
											"<button dojoType=\"dijit.form.Button\" onClick=\"executeApproveEvent('".$myrow['ID']."','".htmlspecialchars($myrow['EVT_TITLE'],ENT_QUOTES)."');\" style=\"height: 50px;\">Accept</button>" .
											"<button dojoType=\"dijit.form.Button\" onClick=\"eventDelete('".$myrow['ID']."','".htmlspecialchars($myrow['EVT_TITLE'],ENT_QUOTES)."');\" style=\"height: 50px;\">Delete</button>" .
										"</td>
									</tr>\n";

								}else{

									echo"
									<tr>
										<td style='padding-right:5px;'><button dojoType=\"dijit.form.Button\" onClick=\"eventDelete('".$myrow['ID']."','".htmlspecialchars($myrow['EVT_TITLE'],ENT_QUOTES)."');\" style=\"height: 50px;\">Delete</button></td>
									</tr>\n";

								}
							}

						 echo "</table>\n";
				echo "</div>\n";

			++$x;
			}

		echo "</div>";

	}//end if $result;
?>